package com.nokia.pc3.core.dac;

import java.io.File;
import java.io.IOException;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

/**
 * Temporary initialization class for populating DAC configuration object. Reads
 * from a json file which contains PC3 properties, including lists of
 * transformers for different MR stages.
 * 
 * @see DAC
 */
public class DACInit {

	private DAC dac;
	private final String config = new String(
			"{\n"
					+ "\"xformName\":\"Raw-MSP-Navtr\",\n"
					+ "\"xformVersion\":\"1.0.1-SNAPSHOT\",\n"
					+ "\"xformation\": \n"
					+ "[ \n"
					+ "{\n"
					+ "\"xformName\": \"MSP-Navtr-ETL\",\n"
					+ "\"xformType\":\"UnstructuredNokiaRecordInputFileFormat\",\n"
					+ "\"xformlist\":\n"
					+ "[\n"
					+ "{ \n"
					+ "\"fname\":\"PhaseAll-Regex\",\n"
					+ "\"fclass\":\"com.nokia.pc3.core.transformers.RegEx1Xfm\",\n"
					+ "\"input\":\"msp_navtr_raw\", \n"
					+ "\"output\":\"msp_navtr_transform\",\n"
					+ "\"labels\":\"entire_record, syslog_utc_datetime, NE_syslog_server_month, NE_syslog_server_day, NE_syslog_server_time, syslog_origin_host, syslog_server_host, static_text, client_ip, request_utc_datetime, http_method, http_full_request, http_response_cd, response_size, request_size, response_time, http_referer, http_user_agent, x_forwarded_for, x_server_by_header, nlp_trace_id\",\n"
					+ "\"args\":\"KCgoPzpKYW4oPzp1YXJ5KT98RmViKD86cnVhcnkpP3xNYXIoPzpjaCk/fEFwcig/OmlsKT98TWF5\\r\\nfEp1big/OmUpP3xKdWwoPzp5KT98QXVnKD86dXN0KT98U2VwKD86dGVtYmVyKT98U2VwdHxPY3Qo\\r\\nPzpvYmVyKT98Tm92KD86ZW1iZXIpP3xEZWMoPzplbWJlcik/KSlccyhcZCspXHMoKD86KD86WzAt\\r\\nMV1bMC05XSl8KD86WzJdWzAtM10pfCg/OlswLTldKSk6KD86WzAtNV1bMC05XSkoPzo6WzAtNV1b\\r\\nMC05XSk/KD86XHM/KD86YW18QU18cG18UE0pKT8pKVxzKCg/Oig/OjI1WzAtNV18MlswLTRdWzAt\\r\\nOV18WzAxXT9bMC05XVswLTldPylcLil7M30oPzoyNVswLTVdfDJbMC00XVswLTldfFswMV0/WzAt\\r\\nOV1bMC05XT8pKSg/IVtcZF0pXHMoXFMrKVxzKFxTKylccygoPzooPzoyNVswLTVdfDJbMC00XVsw\\r\\nLTldfFswMV0/WzAtOV1bMC05XT8pXC4pezN9KD86MjVbMC01XXwyWzAtNF1bMC05XXxbMDFdP1sw\\r\\nLTldWzAtOV0/KSkoPyFbXGRdKVxzKCg/OjJ8MSlcZHszfSg/Oi18XC8pKD86KD86MFsxLTldKXwo\\r\\nPzoxWzAtMl0pKSg/Oi18XC8pKD86KD86MFsxLTldKXwoPzpbMS0yXVswLTldKXwoPzozWzAtMV0p\\r\\nKSg/OlR8XHMpKD86KD86WzAtMV1bMC05XSl8KD86MlswLTNdKSk6KD86WzAtNV1bMC05XSk6KD86\\r\\nWzAtNV1bMC05XSksXGQrKVxzKFxTKylccyhcJy4qP1wnKVxzKFxkKylccyhcZCspXHMoWy0rXVxk\\r\\nKylccyhcZCspXHMoXCcuKj9cJylccyhcJy4qP1wnKVxzKFwnLio/XCcpXHMoXCcuKj9cJylccyhc\\r\\nJy4qP1wnKQ==\\r\\n\"\n"
					+ "}\n"
					+ "],\n"
					+ "\"xformOutlist\":\n"
					+ "[\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.syslog_utc_datetime\",\n"
					+ "\"labelOut\":\"syslog_utc_datetime\",\n"
					+ "\"index\":\"1\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.NE_syslog_server_month\",\n"
					+ "\"labelOut\":\"NE_syslog_server_month\",\n"
					+ "\"index\":\"2\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.NE_syslog_server_day\",\n"
					+ "\"labelOut\":\"NE_syslog_server_day\",\n"
					+ "\"index\":\"3\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.NE_syslog_server_time\",\n"
					+ "\"labelOut\":\"NE_syslog_server_time\",\n"
					+ "\"index\":\"4\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.syslog_origin_host\",\n"
					+ "\"labelOut\":\"syslog_origin_host\",\n"
					+ "\"index\":\"5\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.syslog_server_host\",\n"
					+ "\"labelOut\":\"syslog_server_host\",\n"
					+ "\"index\":\"6\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.static_text\",\n"
					+ "\"labelOut\":\"static_text\",\n"
					+ "\"index\":\"7\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.client_ip\",\n"
					+ "\"labelOut\":\"client_ip\",\n"
					+ "\"index\":\"8\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.request_utc_datetime\",\n"
					+ "\"labelOut\":\"request_utc_datetime\",\n"
					+ "\"index\":\"9\"\n"
					+ "},\n"
					+ "\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.http_method\",\n"
					+ "\"labelOut\":\"http_method\",\n"
					+ "\"index\":\"10\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.http_full_request\",\n"
					+ "\"labelOut\":\"http_full_request\",\n"
					+ "\"index\":\"11\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.http_response_cd\",\n"
					+ "\"labelOut\":\"http_response_cd\",\n"
					+ "\"index\":\"12\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.response_size\",\n"
					+ "\"labelOut\":\"response_size\",\n"
					+ "\"index\":\"13\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.request_size\",\n"
					+ "\"labelOut\":\"request_size\",\n"
					+ "\"index\":\"14\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.response_time\",\n"
					+ "\"labelOut\":\"response_time\",\n"
					+ "\"index\":\"15\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.http_referer\",\n"
					+ "\"labelOut\":\"http_referer\",\n"
					+ "\"index\":\"16\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.http_user_agent\",\n"
					+ "\"labelOut\":\"http_user_agent\",\n"
					+ "\"index\":\"17\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.x_forwarded_for\",\n"
					+ "\"labelOut\":\"x_forwarded_for\",\n"
					+ "\"index\":\"18\"\n"
					+ "},\n"
					+ "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.x_server_by_header\",\n"
					+ "\"labelOut\":\"x_server_by_header\",\n"
					+ "\"index\":\"19\"\n" + "},\n" + "{\n"
					+ "\"labelIn\":\"msp_navtr_transform.nlp_trace_id\",\n"
					+ "\"labelOut\":\"nlp_trace_id\",\n" + "\"index\":\"20\"\n"
					+ "}\n" + "]\n" + "}\n" + "]\n" + "}\n");

	public DACInit() {
		ObjectMapper mapper = new ObjectMapper();
		try {

			// Mock reading a JSON like structure from DAC
			JsonNode rootNode = mapper.readValue(new File(
			// "/tmp/NokiaDACReader2.json"), JsonNode.class);
			//		"/tmp/TestReader1.json"), JsonNode.class);
		"src/main/resources/TestReader1.json"), JsonNode.class);
			dac = mapper.treeToValue(rootNode, DAC.class);
			// Read using embeded string.
			// dac = mapper.readValue(config, DAC.class);

			// JsonNode rootNode = mapper.readValue(new File(
			// "/tmp/NokiaDACReader2.json"), JsonNode.class);
			// dac = mapper.treeToValue(rootNode, DAC.class);

		} catch (JsonGenerationException e) {
			e.printStackTrace();
		} catch (JsonMappingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public DAC getDAC() {
		return dac;
	}

	@Override
	public String toString() {
		return "DACConfig [dac=" + dac + "]";
	}

}
